home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc™ Source Code / Storage / Bento / CM / SymTbMgr.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  6.1 KB  |  154 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        SymTbMgr.h
  3.  
  4.     Contains:    Container Manager Binary Tree Symbol Interfaces
  5.  
  6.     Written by:    Ira L. Ruben
  7.  
  8.     Owned by:    Ed Lai
  9.  
  10.     Copyright:    © 1991-1994 by Apple Computer, Inc., all rights reserved.
  11.  
  12.     Change History (most recent first):
  13.  
  14.          <2>     8/26/94    EL        #1182319 The compare function in
  15.                                     lookUpSymbol now compare name to symbol
  16.                                     rather than symbol to symbol.
  17.          <1>      2/3/94    EL        first checked in
  18.  
  19.     To Do:
  20. */
  21.  
  22. /*---------------------------------------------------------------------------*
  23.  |                                                                           |
  24.  |                         <<<    SymTbMgr.h    >>>                          |
  25.  |                                                                           |
  26.  |              Container Manager Binary Tree Symbol Interfaces              |
  27.  |                                                                           |
  28.  |                               Ira L. Ruben                                |
  29.  |                                 11/18/91                                  |
  30.  |                                                                           |
  31.  |                  Copyright Apple Computer, Inc. 1991-1994                 |
  32.  |                           All rights reserved.                            |
  33.  |                                                                           |
  34.  *---------------------------------------------------------------------------*
  35.  
  36.  The SymbolTableMgr contains all the generic symbol table routines.  They are in the form
  37.  of binary trees.  The three routines cmEnterSymbol(), cmLookupSymbol(), and
  38.  cmForEachSymbol() are the low level generic binary tree manipulators which higher level
  39.  "glue" routines use.
  40.  
  41.  All structs that are to be maintained as binary trees with this package must be of the
  42.  form:
  43.  
  44.                  struct {
  45.                     SymbolLinks theLinks;
  46.                     ...
  47.                 }...;
  48.                 
  49.  In other words, a field (any name will do) of type SymbolLinks MUST be the first field
  50.  of the structure.  The caller allocates all the struct symbol table entries.  This
  51.  package enters them into a symbol table based on a tree root pointer and maintains the
  52.  SymbolLinks.
  53.  
  54.  Being a generic package the links have to be at a know place in an otherwise arbitrary
  55.  struct.  Hence the position requirement.
  56. */
  57.  
  58.  
  59. #ifndef __SYMMGR__
  60. #define __SYMMGR__
  61.  
  62.  
  63. #ifndef __CMTYPES__
  64. #include "CMTypes.h"
  65. #endif
  66. #ifndef __CM_API_TYPES__
  67. #include "CMAPITyp.h"
  68. #endif
  69.  
  70. struct SessionGlobalData;
  71.                                                                     CM_CFUNCTIONS
  72.  
  73.  
  74. struct SymbolLinks {                                                        /* must be the first field in any symbol*/
  75.     struct SymbolLinks *lLink, *rLink;                        /*        left/right binary tree links            */
  76. };
  77. typedef struct SymbolLinks SymbolLinks, *SymbolLinksPtr;
  78.  
  79.  
  80. void *cmEnterSymbol(const void *symbol, void **root, Boolean *dup,
  81.                                         int (*compare)(const void *, const void *));
  82.     /*
  83.     Enter the specified symbol into its own binary tree symbol table with the specified root.
  84.     The function returns a pointer to the entry if entered.  If the entry is already there,
  85.     the pointer to the dup entry is returned, dup is set to true, and no other action taken.
  86.     
  87.     It is assumed the space for the new symbol has already been allocated and its pointer
  88.     passed as the symbol here.
  89.     
  90.     The binary tree is searched utilizing a comparison function provided by the caller.
  91.     Compare is function that takes as arguments pointers to two symbols and returns -1 if the
  92.     first symbol is "less than" the second, 1 if the first symbol is "greater than" the 
  93.     second, and 0 if the tow symbols are equal.
  94.     */
  95.  
  96.  
  97. void *cmLookupSymbol(const CM_UCHAR *name, const void *root,
  98.                                           int (*compare)(const void *, const CM_UCHAR *));
  99.  /*
  100.     Look up the specified symbol in its binary tree symbol table which starts at the
  101.     specified root.  Return the pointer to it if found and NULL if not found.
  102.  
  103.     The binary tree is searched utilizing a comparison function provided by the caller. 
  104.     Compare is function that takes as arguments pointers to two symbols and returns -1 if the
  105.     first symbol is "less than" the second, 1 if the first symbol is "greater than" the 
  106.     second, and 0 if the tow symbols are equal.
  107.      
  108.     It used to be that both arguments of compare are symbols, but that requires the
  109.     temporary geneation of a symbol during lookup. So we change the comparision to
  110.     a symbol and a name to improve the performance.
  111.     */
  112.  
  113.  
  114. void cmForEachSymbol(const void *symbol, CMRefCon refCon,
  115.                                           void (*action)(void *symbol, CMRefCon refCon));
  116.     /*
  117.     Do (call) the specified action for each entry in a binary tree symbol table. This
  118.     routine recursively traverses the binary tree calling (*action)() on each entry visited.
  119.     The pointer to the entry is passed to the action routine along with a "refCon" which the
  120.     caller can use as a communication facility to convey additional info to the action
  121.     routine.
  122.     
  123.     The search in the binary tree starts at the specified symbol location.  Generally this
  124.     will be a root of a tree, but need not be.  Tree traversal is such that the symbols are
  125.     visited in "ascending" order, i.e., whatever order that was used by the compare
  126.     function passed to cmEnterSymbol().
  127.     */
  128.     
  129.     
  130. typedef void (*SymbolAction)(void *, CMRefCon);
  131.     /*
  132.     The cmForEachSymbol() action routine is defined as the generic action routine to call
  133.     for a table consisting of symbols of a particular type.  Calling cmForEachSymbol() will
  134.     thus require casting the callers action routine to the generic type.  This typedef is
  135.     used for that purpose.  It must be here under the exter "C" C++ linkage specification
  136.     so that the cast, like the cmForEachSymbol() proptotype uses C calling conventions.
  137.     */ 
  138.     
  139.     
  140. void cmFreeAllSymbols(void **root, struct SessionGlobalData *sessionData);
  141.     /*
  142.   This routine takes a root of a binary tree symbol table and deletes ALL the entries in
  143.   the table.  The root pointer is returned as NULL.
  144.  
  145.     Note, that SymbolTableMgr routines are low level routines used in a number of contexts.
  146.     Here we need to uutilize the container memory deallocator handler.  Because we don't
  147.     know the context, which may be global, the session global data pointer is passed and we
  148.     access the handler through that.
  149.     */
  150.     
  151.     
  152.                                                           CM_END_CFUNCTIONS
  153. #endif
  154.